////////////////////////////////////////////////
// File: AdvertisementController.java
// Description: Enter summary here after generation.
// Date: 2016-09-19 15:32:14
// Web: http://www.elanzhou.com/
////////////////////////////////////////////////
package com.mvc.controller;

import java.io.IOException;
import java.math.BigInteger;
import java.util.List;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.mvc.entity.Advertisement;
import com.mvc.entity.Business;
import com.mvc.entity.Meminfo;
import com.mvc.entity.News;
import com.mvc.service.AdvertisementService;
import com.mvc.service.BusinessService;
import com.mvc.service.GoodsService;
import com.mvc.service.HomeService;
import com.mvc.service.MarketService;
import com.mvc.service.MeminfoService;
import com.mvc.service.NewsService;
import com.mvc.service.SyscateService;
import com.mvc.service.SyschannelService;
import com.pub.MyJson;
import com.pub.Page;
import com.aspose.cells.Cells;
import com.aspose.cells.Workbook;
import com.aspose.cells.Worksheet;

@Controller
@RequestMapping("/")
public class HomeController {
	protected final transient Log logger = LogFactory
			.getLog(HomeController.class);
	@Autowired
	private MeminfoService meminfoService;
	@Autowired
	private HomeService homeService;
	@Autowired
	private NewsService newsService;
	@Autowired
	private MarketService marketService;
	@Autowired
	private GoodsService goodsService;
	@Autowired
	private SyschannelService syschannelService;
	@Autowired
	private BusinessService businessService;
	@Autowired
	private SyscateService syscateService;
	@Autowired
	private AdvertisementService advertisementService;

	public HomeController() {
	}

	/* 列表 */
	@RequestMapping("Index.Action")
	public String Index(HttpSession session, ModelMap modelMap) {
		String newson = "";
		String marketon = "";
		String goodson = "";
		String businesson = "";
		String fuwuon = "";
		modelMap.put("fuwuon", fuwuon);
		modelMap.put("newson", newson);
		modelMap.put("marketon", marketon);
		modelMap.put("goodson", goodson);
		modelMap.put("businesson", businesson);
		modelMap.put("homeSercice", homeService);
		Meminfo smeminfo = (Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo", smeminfo);
		return "/Home/Index";

	}

	@RequestMapping("Syscate.Action")
	public String Syscate(HttpSession session, ModelMap modelmap) {
		String newson = "";
		String marketon = "";
		String goodson = "";
		String businesson = "";
		String fuwuon = "";
		modelmap.put("newson", newson);
		modelmap.put("marketon", marketon);
		modelmap.put("goodson", goodson);
		modelmap.put("businesson", businesson);
		modelmap.put("fuwuon", fuwuon);
		modelmap.put("homeSercice", homeService);
		Meminfo smeminfo = (Meminfo) session.getAttribute("SessionMem");
		modelmap.put("smeminfo", smeminfo);
		return "/Home/Syscate";

	}

	@RequestMapping("SyscateDetail.Action")
	public String SyscateDetail(HttpSession session, ModelMap modelmap,
			HttpServletRequest request) {
		String newson = "";
		String marketon = "";
		String goodson = "";
		String businesson = "";
		String fuwuon = "";
		modelmap.put("newson", newson);
		modelmap.put("marketon", marketon);
		modelmap.put("goodson", goodson);
		modelmap.put("businesson", businesson);
		modelmap.put("fuwuon", fuwuon);
		modelmap.put("homeSercice", homeService);
		String ID = request.getParameter("ID");
		com.mvc.entity.Syscate syscate = syscateService.getSyscate(ID);
		modelmap.put("syscate", syscate);
		Meminfo smeminfo = (Meminfo) session.getAttribute("SessionMem");
		modelmap.put("smeminfo", smeminfo);
		return "/Home/SyscateDetail";

	}

	@RequestMapping("ScNews.Action")
	public String ScNews(HttpSession session, HttpServletRequest request,
			ModelMap modelMap, String pageNo, String Ajax) {
		String newson = "";
		String marketon = "";
		String goodson = "on";
		String businesson = "";
		String fuwuon = "";
		modelMap.put("newson", newson);
		modelMap.put("marketon", marketon);
		modelMap.put("goodson", goodson);
		modelMap.put("businesson", businesson);
		modelMap.put("fuwuon", fuwuon);
		modelMap.put("homeSercice", homeService);
		Meminfo smeminfo = (Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo", smeminfo);
		String CID = request.getParameter("CID");
		com.mvc.entity.Syscate syscate = syscateService.getSyscate(CID);
		modelMap.put("syscate", syscate);
		Page page = new Page();
		List list = new ArrayList();
		page.setPageNox(pageNo);
		page.setPageSize(15);
		page.setVal(",\"CID\":" + CID);
		String hql = "select a from News a where a.Catename='"
				+ syscate.getCatename() + "' order by a.ID desc";
		list = newsService.getNewsList(hql, page);
		String counthql = "select count(*) from  News a where a.Catename='"
				+ syscate.getCatename() + "'";
		page.setPageCount(newsService.getCount(counthql, page));
		modelMap.put("page", page);
		modelMap.put("list", list);
		if (Ajax != null && Ajax.equals("Ajax")) {
			return "/Home/ScNewsList";
		} else {
			return "/Home/ScNews";
		}

	}

	/* 列表 */

	@RequestMapping("RegistNameCheck.Action")
	public void RegistNameCheck(HttpServletRequest request,
			HttpServletResponse response) {
		// System.out.println("==============="+request.getParameter("Memname")+"==============");
		String Memname = request.getParameter("Memname");
		Meminfo mi = meminfoService.getMeminfoByName(Memname);
		try {
			if (mi == null) {
				response.getWriter().print("{\"valid\":true}");
			} else {
				response.getWriter().print("{\"valid\":false}");
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@RequestMapping("BusinessDetail.Action")
	public String BusinessDetail(HttpServletRequest request,
			HttpSession session, ModelMap modelMap, String pageNo, String Ajax) {
		String newson = "";
		String marketon = "";
		String goodson = "";
		String businesson = "on";
		modelMap.put("newson", newson);
		modelMap.put("marketon", marketon);
		modelMap.put("goodson", goodson);
		modelMap.put("businesson", businesson);

		modelMap.put("homeSercice", homeService);
		Meminfo smeminfo = (Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo", smeminfo);
		String ID = request.getParameter("ID");
		Business business = (Business) businessService.getBusiness(ID);
		modelMap.put("business", business);
		return "/Home/BusinessDetail";

	}

	@RequestMapping("GoodsDetail.Action")
	public String GoodsDetail(HttpServletRequest request, HttpSession session,
			ModelMap modelMap, String pageNo, String Ajax) {
		String newson = "";
		String marketon = "";
		String goodson = "on";
		String businesson = "";
		String fuwuon = "";
		modelMap.put("fuwuon", fuwuon);
		modelMap.put("newson", newson);
		modelMap.put("marketon", marketon);
		modelMap.put("goodson", goodson);
		modelMap.put("businesson", businesson);
		modelMap.put("homeSercice", homeService);
		Meminfo smeminfo = (Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo", smeminfo);
		String ID = request.getParameter("ID");
		com.mvc.entity.Goods goods = (com.mvc.entity.Goods) goodsService
				.getGoods(ID);
		modelMap.put("goods", goods);
		Meminfo meminfo = (Meminfo) meminfoService.getMeminfoByName(goods
				.getMembername());
		modelMap.put("meminfo", meminfo);
		return "/Home/GoodsDetail";
	}

	@RequestMapping("Business.Action")
	public String Business(HttpSession session, ModelMap modelMap,
			String pageNo, String Ajax) {
		String newson = "";
		String marketon = "";
		String goodson = "";
		String businesson = "on";
		String fuwuon = "";
		modelMap.put("fuwuon", fuwuon);
		modelMap.put("newson", newson);
		modelMap.put("marketon", marketon);
		modelMap.put("goodson", goodson);
		modelMap.put("businesson", businesson);

		modelMap.put("homeSercice", homeService);
		Meminfo smeminfo = (Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo", smeminfo);
		Page page = new Page();
		page.setPageNox(pageNo);
		page.setPageSize(15);
		String hql = "select a from Business a order by a.ID desc";
		List list = businessService.getBusinessList(hql, page);
		String counthql = "select count(*) from Business a";
		page.setPageCount(businessService.getCount(counthql, page));
		modelMap.put("page", page);
		modelMap.put("list", list);
		if (Ajax != null && Ajax.equals("Ajax")) {
			return "/Home/BusinessList";
		} else {
			return "/Home/Business";
		}

	}

	@RequestMapping("Market.Action")
	public String Market(HttpSession session, HttpServletRequest request,
			ModelMap modelMap, String pageNo, String Ajax) {
		String newson = "";
		String marketon = "on";
		String goodson = "";
		String businesson = "";
		String fuwuon = "";
		modelMap.put("fuwuon", fuwuon);
		modelMap.put("newson", newson);
		modelMap.put("marketon", marketon);
		modelMap.put("goodson", goodson);
		modelMap.put("businesson", businesson);
		Meminfo smeminfo = (Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo", smeminfo);
		modelMap.put("homeSercice", homeService);
		Page page = new Page();
		List list = new ArrayList();

		page.setPageNox(pageNo);
		page.setPageSize(15);

		String hql = "select a from Market a  order by a.ID desc";
		list = marketService.getMarketList(hql, page);
		String counthql = "select count(*) from  Market a";
		page.setPageCount(marketService.getCount(counthql, page));

		modelMap.put("page", page);
		modelMap.put("list", list);
		if (Ajax != null && Ajax.equals("Ajax")) {
			return "/Home/MarketList";
		} else {
			return "/Home/Market";
		}

	}

	// 行情
	@RequestMapping("ScGoods.Action")
	public String ScGoods(HttpSession session, HttpServletRequest request,
			ModelMap modelMap, String pageNo, String Ajax) {
		String newson = "";
		String marketon = "";
		String goodson = "on";
		String businesson = "";
		String fuwuon = "";
		modelMap.put("newson", newson);
		modelMap.put("marketon", marketon);
		modelMap.put("goodson", goodson);
		modelMap.put("businesson", businesson);
		modelMap.put("fuwuon", fuwuon);
		modelMap.put("homeSercice", homeService);
		String Goodstype = request.getParameter("Goodstype");
		modelMap.put("GoodsType", Goodstype);
		String CID = request.getParameter("CID");
		com.mvc.entity.Syscate syscate = syscateService.getSyscate(CID);
		modelMap.put("syscate", syscate);
		Meminfo smeminfo = (Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo", smeminfo);
		Page page = new Page();
		List list = new ArrayList();
		if (Goodstype == null) {
			page.setPageNox(pageNo);
			page.setPageSize(15);
			page.setVal("");
			String hql = "select a from Goods a where a.Status='已审核' and a.Catename='"
					+ syscate.getCatename() + "' order by a.ID desc";
			list = goodsService.getGoodsList(hql, page);
			String counthql = "select count(*) from  Goods a where a.Status='已审核' and a.Catename='"
					+ syscate.getCatename() + "'";
			page.setPageCount(goodsService.getCount(counthql, page));
		} else {
			page.setPageNox(pageNo);
			page.setPageSize(15);
			page.setVal(",'CID':" + syscate.getId() + ",'Goodstype':'"
					+ Goodstype + "'");
			String hql = "select a from Goods a where a.Goodstype='"
					+ Goodstype + "' and  a.Status='已审核' and a.Catename='"
					+ syscate.getCatename() + "'   order by a.ID desc";
			list = goodsService.getGoodsList(hql, page);
			String counthql = "select count(*) from  Goods a where a.Goodstype='"
					+ Goodstype
					+ "'  and a.Status='已审核' and a.Catename='"
					+ syscate.getCatename() + "'";
			page.setPageCount(goodsService.getCount(counthql, page));
			modelMap.put("Goodstype", Goodstype);
		}

		modelMap.put("page", page);
		modelMap.put("list", list);
		if (Ajax != null && Ajax.equals("Ajax")) {
			return "/Home/ScGoodsList";
		} else {
			return "/Home/ScGoods";
		}

	}

	@RequestMapping("Goods.Action")
	public String Goods(HttpSession session, HttpServletRequest request,
			ModelMap modelMap, String pageNo, String Ajax) {
		String newson = "";
		String marketon = "";
		String goodson = "on";
		String businesson = "";
		String fuwuon = "";
		modelMap.put("fuwuon", fuwuon);
		modelMap.put("newson", newson);
		modelMap.put("marketon", marketon);
		modelMap.put("goodson", goodson);
		modelMap.put("businesson", businesson);
		modelMap.put("homeSercice", homeService);
		Meminfo smeminfo = (Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo", smeminfo);
		String Goodstype = request.getParameter("Goodstype");
		Page page = new Page();
		List list = new ArrayList();
		if (Goodstype == null) {
			page.setPageNox(pageNo);
			page.setPageSize(15);
			page.setVal("");
			String hql = "select a from Goods a where a.Status='已审核' order by a.ID desc";
			list = goodsService.getGoodsList(hql, page);
			String counthql = "select count(*) from  Goods a where a.Status='已审核' ";
			page.setPageCount(goodsService.getCount(counthql, page));
		} else {
			page.setPageNox(pageNo);
			page.setPageSize(15);
			page.setVal(",'Goodstype':'" + Goodstype + "'");
			String hql = "select a from Goods a where a.Goodstype='"
					+ Goodstype + "' and  a.Status='已审核'   order by a.ID desc";
			list = goodsService.getGoodsList(hql, page);
			String counthql = "select count(*) from  Goods a where a.Goodstype='"
					+ Goodstype + "'  and a.Status='已审核'";
			page.setPageCount(goodsService.getCount(counthql, page));
			modelMap.put("Goodstype", Goodstype);
		}

		modelMap.put("page", page);
		modelMap.put("list", list);
		if (Ajax != null && Ajax.equals("Ajax")) {
			return "/Home/GoodsList";
		} else {
			return "/Home/Goods";
		}

	}

	@RequestMapping("News.Action")
	public String News(HttpSession session, HttpServletRequest request,
			ModelMap modelMap, String pageNo, String Ajax) {
		String newson = "on";
		String marketon = "";
		String goodson = "";
		String businesson = "";
		String fuwuon = "";
		modelMap.put("fuwuon", fuwuon);
		modelMap.put("newson", newson);
		modelMap.put("marketon", marketon);
		modelMap.put("goodson", goodson);
		modelMap.put("businesson", businesson);
		modelMap.put("homeSercice", homeService);
		Meminfo smeminfo = (Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo", smeminfo);
		String Syschannelname = request.getParameter("Syschannel");
		modelMap.put("Syschannelname", Syschannelname);
		List slist = syschannelService
				.getListByHql("select a from Syschannel a");
		modelMap.put("slist", slist);

		Page page = new Page();
		List list = new ArrayList();
		if (Syschannelname != null) {
			page.setPageNox(pageNo);
			page.setPageSize(15);
			page.setVal(",'Syschannel':'" + Syschannelname + "'");
			String hql = "select a from News a where a.Syschannel='"
					+ Syschannelname + "' order by a.ID desc";
			list = newsService.getNewsList(hql, page);
			String counthql = "select count(*) from  News a where a.Syschannel='"
					+ Syschannelname + "'";
			page.setPageCount(newsService.getCount(counthql, page));
		} else {

			page.setPageNox(pageNo);
			page.setPageSize(15);
			// page.setVal(",'Syschannel':'"+Syschannel+"'");
			String hql = "select a from News a  order by a.ID desc";
			list = newsService.getNewsList(hql, page);
			String counthql = "select count(*) from  News a";
			page.setPageCount(newsService.getCount(counthql, page));
		}
		modelMap.put("page", page);
		modelMap.put("list", list);
		if (Ajax != null && Ajax.equals("Ajax")) {
			return "/Home/NewsList";
		} else {
			return "/Home/News";
		}

	}

	/* 新闻 */
	@RequestMapping("NewsDetail.Action")
	public String NewsDetail(HttpSession session, HttpServletRequest request,
			ModelMap modelMap) {
		String newson = "on";
		String marketon = "";
		String goodson = "";
		String businesson = "";
		String fuwuon = "";
		modelMap.put("fuwuon", fuwuon);
		modelMap.put("newson", newson);
		modelMap.put("marketon", marketon);
		modelMap.put("goodson", goodson);
		modelMap.put("businesson", businesson);
		modelMap.put("homeSercice", homeService);
		Meminfo smeminfo = (Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo", smeminfo);
		String ID = request.getParameter("ID");
		News news = (News) newsService.getNews(ID);
		modelMap.put("news", news);
		return "/Home/NewsDetail";
	}

	/* 广告 */
	@RequestMapping("Ad.Action")
	public String Ad(HttpSession session, HttpServletRequest request,
			ModelMap modelMap) {
		String newson = "";
		String marketon = "";
		String goodson = "";
		String businesson = "";
		String fuwuon = "on";
		modelMap.put("fuwuon", fuwuon);
		modelMap.put("newson", newson);
		modelMap.put("marketon", marketon);
		modelMap.put("goodson", goodson);
		modelMap.put("businesson", businesson);
		modelMap.put("homeSercice", homeService);
		Meminfo smeminfo = (Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo", smeminfo);
		String ID = request.getParameter("ID");
		Advertisement adt = (Advertisement) advertisementService
				.getAdvertisement(ID);
		modelMap.put("adt", adt);
		return "/Home/Ad";
	}

	/* 服务 */
	@RequestMapping("Fuwu.Action")
	public String Fuwu(HttpSession session, HttpServletRequest request,
			ModelMap modelMap) {
		String newson = "";
		String marketon = "";
		String goodson = "";
		String businesson = "";
		String fuwuon = "on";
		modelMap.put("newson", newson);
		modelMap.put("marketon", marketon);
		modelMap.put("goodson", goodson);
		modelMap.put("businesson", businesson);
		modelMap.put("fuwuon", fuwuon);
		modelMap.put("homeSercice", homeService);
		Meminfo smeminfo = (Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo", smeminfo);
		String hql = "select a from Advertisement a  where a.Adtype='一华服务' order by a.ID desc ";
		List slist = advertisementService.getListByHql(hql);
		Advertisement adt = null;
		if (!slist.isEmpty()) {
			adt = (Advertisement) slist.get(0);
		}
		modelMap.put("adt", adt);
		return "/Home/Fuwu";
	}

	/* 列表 */
	@RequestMapping("Welcome.do")
	public String Welcome(HttpSession session, ModelMap modelMap) {
		Meminfo smeminfo = (Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo", smeminfo);
		return "/Home/Welcome";

	}

	/* 列表 */
	@RequestMapping("Login.Action")
	public String Login() {
		return "/Home/Login";

	}

	/* 列表 */
	@RequestMapping("Logout.Action")
	public void Logout(HttpSession session, ModelMap modelMap,
			HttpServletResponse response) {

		session.invalidate();
		String str = "{\"statusCode\":200,\"message\":\"退出成功\",\"callbackType\":\"forward\",\"forwardUrl\":\"/Login.Action\"}";
		try {
			response.getWriter().print(str);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/* 列表 */
	@RequestMapping("Member.do")
	public String Member(HttpSession session, ModelMap modelMap) {
		Meminfo smeminfo = (Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo", smeminfo);
		return "/Home/Member";

	}

	/* 列表 */
	@RequestMapping("Bank.do")
	public String Bank(HttpSession session, ModelMap modelMap) {
		Meminfo smeminfo = (Meminfo) session.getAttribute("SessionMem");
		modelMap.put("smeminfo", smeminfo);
		return "/Home/Bank";

	}

	@RequestMapping("CheckUser.Action")
	public void CheckUser(HttpSession session, String username,
			String password, String verify, HttpServletResponse response) {
		String myverify = (String) session.getAttribute("validateCode");
		myverify = myverify.toLowerCase();
		verify = verify.toLowerCase();
		if (verify.equals(myverify)) {
			Meminfo user = (Meminfo) meminfoService.getMeminfoByName(username);
			if (user != null) {
				if (user.getMempass().equals(getMD5(password))) {
					if (user.getStatus().equals("未审核")) {
						try {
							MyJson myjson = new MyJson();
							myjson.setStatusCode(300);
							myjson.setMessage("登录失败,请等待审核！");
							myjson.setCallbackType("forward");
							myjson.setForwardUrl("#");
							response.getWriter().print(myjson.getJson());
						} catch (IOException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
							// log.error(e.getMessage());
						}
					} else {
						session.setAttribute("SessionMem", user);
						try {
							MyJson myjson = new MyJson();
							myjson.setStatusCode(200);
							myjson.setMessage("登陆成功");
							myjson.setCallbackType("forward");
							switch (user.getRolename()) {
							case ("管理员"):
								myjson.setForwardUrl("/Welcome.do");
								break;
							case ("银行"):
								myjson.setForwardUrl("/Bank.do");
								break;
							case ("员工"):
								myjson.setForwardUrl("/Employee.do");
								break;
							default:
								myjson.setForwardUrl("/Member.do");
								break;
							}
							response.getWriter().print(myjson.getJson());
						} catch (IOException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
							// log.error(e.getMessage());
						}
					}
				} else {
					try {
						MyJson myjson = new MyJson();
						myjson.setStatusCode(300);
						myjson.setMessage("登录失败");
						myjson.setCallbackType("forward");
						myjson.setForwardUrl("#");
						response.getWriter().print(myjson.getJson());
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
						// log.error(e.getMessage());
					}
				}
			} else {
				try {
					MyJson myjson = new MyJson();
					myjson.setStatusCode(300);
					myjson.setMessage("登录失败,用户名不存在");
					myjson.setCallbackType("forward");
					myjson.setForwardUrl("#");
					response.getWriter().print(myjson.getJson());
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					// log.error(e.getMessage());
				}
			}
		} else {
			try {
				MyJson myjson = new MyJson();
				myjson.setStatusCode(300);
				myjson.setMessage("验证码错误，请刷新验证码！");
				myjson.setCallbackType("forward");
				myjson.setForwardUrl("#");
				response.getWriter().print(myjson.getJson());
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				// log.error(e.getMessage());
			}
		}
	}

	/* 列表 */
	@RequestMapping("Regist.Action")
	public String Regist() {
		return "/Home/Regist";

	}

	/* 保存 */
	@RequestMapping("RegistOk.Action")
	public void RegistOk(HttpServletResponse response,
			HttpServletRequest request, ModelMap modelMap, HttpSession session) {
		try {

			Meminfo meminfo = new Meminfo();
			boolean tag = true;
			String Msg = "信息保存成功";

			if (tag) {

				String FieldMemname = (String) request.getParameter("Memname");

				if (((FieldMemname != null) & (!FieldMemname.trim().equals("")))) {
					FieldMemname = FieldMemname.trim();
					meminfo.setMemname(FieldMemname);
					Meminfo mi = meminfoService.getMeminfoByName(FieldMemname);

					if (mi == null) {

					} else {
						tag = false;
						Msg = "会员名称已存在！";
					}
				}
			} else {
				tag = false;
				Msg = "会员名称不能为空！";
			}

			if (tag) {

				String FieldMempass = (String) request.getParameter("Mempass");

				if (((FieldMempass != null) & (!FieldMempass.trim().equals("")))) {
					FieldMempass = FieldMempass.trim();
					meminfo.setMempass(getMD5(FieldMempass));

				} else {
					tag = false;
					Msg = "会员密码不能为空！";
				}
			}

			if (tag) {

				String FieldRolename = (String) request
						.getParameter("Rolename");

				if (((FieldRolename != null) & (!FieldRolename.trim()
						.equals("")))) {
					FieldRolename = FieldRolename.trim();
					meminfo.setRolename(FieldRolename);

				} else {
					tag = false;
					Msg = "角色名称不能为空！";
				}
			}

			if (tag) {

				String FieldCompanyname = (String) request
						.getParameter("Companyname");

				if (((FieldCompanyname != null) & (!FieldCompanyname.trim()
						.equals("")))) {
					FieldCompanyname = FieldCompanyname.trim();
					meminfo.setCompanyname(FieldCompanyname);

				} else {
					tag = false;
					Msg = "公司名称不能为空！";
				}
			}

			if (tag) {

//				String FieldPrivince = (String) request
//						.getParameter("Privince");
				String FieldPrivince =" ";
				meminfo.setPrivince(FieldPrivince);
//				if (((FieldPrivince != null) & (!FieldPrivince.trim()
//						.equals("")))) {
//					FieldPrivince = FieldPrivince.trim();
//					meminfo.setPrivince(FieldPrivince);
//
//				} else {
//					tag = false;
//					Msg = "所在省份不能为空！";
//				}
			}

			if (tag) {

//				String FieldCity = (String) request.getParameter("City");
				
				String FieldCity = " ";
				meminfo.setCity(FieldCity);

//				if (((FieldCity != null) & (!FieldCity.trim().equals("")))) {
//					FieldCity = FieldCity.trim();
//					meminfo.setCity(FieldCity);
//
//				} else {
//					tag = false;
//					Msg = "所在市州不能为空！";
//				}
			}

			if (tag) {

//				String FieldDistrict = (String) request
//						.getParameter("District");
				
				String FieldDistrict = " ";
				meminfo.setDistrict(FieldDistrict);

//				if (((FieldDistrict != null) & (!FieldDistrict.trim()
//						.equals("")))) {
//					FieldDistrict = FieldDistrict.trim();
//					meminfo.setDistrict(FieldDistrict);
//
//				} else {
//					tag = false;
//					Msg = "所在县区不能为空！";
//				}
			}

			if (tag) {

				String FieldContactman = (String) request
						.getParameter("Contactman");

				if (((FieldContactman != null) & (!FieldContactman.trim()
						.equals("")))) {
					FieldContactman = FieldContactman.trim();
					meminfo.setContactman(FieldContactman);

				} else {
					tag = false;
					Msg = "联系人不能为空！";
				}
			}

			if (tag) {

				String FieldContacttel = (String) request
						.getParameter("Contacttel");

				if (((FieldContacttel != null) & (!FieldContacttel.trim()
						.equals("")))) {
					FieldContacttel = FieldContacttel.trim();
					meminfo.setContacttel(FieldContacttel);

				} else {
					tag = false;
					Msg = "联系电话不能为空！";
				}
			}

			if (tag) {

//				String FieldAddress = (String) request.getParameter("Address");
				String FieldAddress = " ";
				meminfo.setAddress(FieldAddress);

//				if (((FieldAddress != null) & (!FieldAddress.trim().equals("")))) {
//					FieldAddress = FieldAddress.trim();
//					meminfo.setAddress(FieldAddress);
//
//				} else {
//					tag = false;
//					Msg = "地址不能为空！";
//				}
			}

			meminfo.setStatus("已审核");

			MyJson mj = new MyJson();
			if (tag) {
				meminfoService.Save(meminfo);
				mj.setStatusCode(200);
			} else {
				mj.setStatusCode(300);
			}
			mj.setMessage(Msg);
			mj.setForwardUrl("/Login.Action");
			mj.setCallbackType("forward");
			String str = mj.getJson();
			response.getWriter().print(str);
		} catch (Exception e) {
			logger.error(e.getMessage());
			e.printStackTrace();
		}
	}

	public static String getMD5(String str) {
	    try {
	        // 生成一个MD5加密计算摘要
	        MessageDigest md = MessageDigest.getInstance("MD5");
	        // 计算md5函数
	        md.update(str.getBytes());
	        // digest()最后确定返回md5 hash值，返回值为8为字符串。因为md5 hash值是16位的hex值，实际上就是8位的字符
	        // BigInteger函数则将8位的字符串转换成16位hex值，用字符串来表示；得到字符串形式的hash值
	        return new BigInteger(1, md.digest()).toString(16);
	    } catch (NoSuchAlgorithmException e) {  
            e.printStackTrace();  
            return null;  
        }  
	}
}
